home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Programming / tek / exec.h < prev    next >
C/C++ Source or Header  |  2001-05-13  |  7KB  |  202 lines

  1.  
  2. #ifndef _TEK_EXEC_H
  3. #define    _TEK_EXEC_H
  4.  
  5. /*
  6. **    tek/exec.h
  7. **    tasks, signals, msgports
  8. */
  9.  
  10. #include <tek/mem.h>
  11.  
  12.  
  13. /* 
  14. **    task structure
  15. **
  16. **    consider it private and access it with the supplied accessor
  17. **    macros, so that your code won't break once this structure gets
  18. **    blackboxed.
  19. */
  20.  
  21. typedef    struct                    /* task */
  22. {
  23.     THNDL handle;                /* object handle */
  24.     TAPTR basetask;                /* base task (may be backptr to this task) */
  25.  
  26.     TVOID (*func)(TAPTR);        /* user entry function */
  27.     TBOOL (*initfunc)(TAPTR);    /* user init function in child context */
  28.  
  29.     TAPTR userdata;                /* user/init data */
  30.  
  31.     TKNOB thread;                /* kernel thread object */
  32.     TKNOB timer;                /* kernel timer object */
  33.  
  34.     TMMU heapmmu;                /* heap memory manager */
  35.     TAPTR heapallocator;        /* heapmmu's underlying allocator */
  36.  
  37.     TKNOB runlock;                /* run-environment lock */
  38.  
  39.     TKNOB statusevent;            /* status change event */
  40.     TUINT status;                /* task status */
  41.  
  42.     TKNOB siglock;                /* signal lock */
  43.     TKNOB sigevent;                /* signal event */
  44.     TUINT sigstate;                /* current signal state */
  45.     TUINT sigfree;                /* free signals */
  46.     TUINT sigused;                /* used signals */
  47.  
  48.     TAPTR port;                    /* task's primaray async msgport */
  49.     TAPTR syncreplyport;        /* task's internal msgport for synchronized replies */
  50.     
  51.     TMMU *msgmmu;                /* ptr to basetask message memory manager */
  52.  
  53. }    TTASK;
  54.  
  55.  
  56. /* 
  57. **    task status
  58. **
  59. **    applications never need to query these flags.
  60. */
  61.  
  62. #define TTASK_STATUS_INITIALIZING    0        /* task is initializing */
  63. #define TTASK_STATUS_RUNNING        1        /* task is running */    
  64. #define TTASK_STATUS_FINISHED        2        /* task has concluded */
  65. #define TTASK_STATUS_FAILED            3        /* task failed to initialize and was never running in tekspace */
  66.  
  67.  
  68. typedef struct                        /* lock */
  69. {
  70.     THNDL handle;                    /* object handle */
  71.     TKNOB lock;                        /* kernel lock object */
  72. }    TLOCK;
  73.  
  74.  
  75. typedef struct                        /* message communication port */
  76. {
  77.     THNDL handle;                    /* object handle */
  78.     TKNOB lock;                        /* kernel lock object */
  79.     TLIST msglist;                    /* list of queued messages */
  80.     TAPTR sigtask;                    /* task to be signalled on msg arrival */
  81.     TUINT signal;                    /* signal to appear in sigtask */
  82.     TAPTR proxy;                    /* proxy object for this port */
  83.     TAPTR reserved[2];
  84. }    TPORT;
  85.  
  86.  
  87. /* 
  88. **    task entry and init functions
  89. */
  90.  
  91. typedef TVOID (*TTASKFUNC)(TAPTR task);
  92. typedef TBOOL (*TTASKINITFUNC)(TAPTR task);
  93.  
  94.  
  95. /* 
  96. **    task signals
  97. **
  98. **    note: currently there are 31 free user signals, but the number of
  99. **    reserved signals (like TTASK_SIG_ABORT) may grow in the future.
  100. **    TEKlib guarantees that a newly created task's upper 16 signal bits
  101. **    (0x8000000 through 0x00010000) will remain available to the user.
  102. **    more free user signals (if available) can be obtained safely with
  103. **    TAllocSignal(). allocation is recommended anyway.
  104. */
  105.  
  106. #define TTASK_MAX_SIGNALS            32
  107. #define TTASK_SIG_ABORT                0x00000001
  108. #define TTASK_SIG_RESERVED             TTASK_SIG_ABORT
  109. #define TTASK_SIG_USER                 0xffff0000
  110.  
  111.  
  112. /* 
  113. **    task tags
  114. */
  115.  
  116. #define TTASKTAGS_                    (TTAG_USER + 0x300)
  117. #define TTask_MMU                    (TTAG) (TTASKTAGS_ + 0)        /* parent memory manager */
  118. #define TTask_InitFunc                (TTAG) (TTASKTAGS_ + 1)        /* child init function */
  119. #define TTask_UserData                (TTAG) (TTASKTAGS_ + 2)        /* ptr to user/init data */
  120. #define TTask_HeapMMU                (TTAG) (TTASKTAGS_ + 3)        /* memory manager for task's heap space */
  121. #define TTask_CreatePort            (TTAG) (TTASKTAGS_ + 4)        /* create a message port in task's context */
  122.  
  123.  
  124. /* 
  125. **    TFLOAT time support macros
  126. */
  127.  
  128. #define TTIMETOF(t)                 (((TFLOAT) (t)->sec) + 0.000001f * ((TFLOAT) (t)->usec))
  129. #define TFTOTIME(f,t)                (t)->sec = (TUINT) (f); (t)->usec = (TUINT) (((f) - (t)->sec) * 1000000);
  130. #define TTimeDelayF(task,f)            { TTIME t; TFTOTIME(f,&t); TTimeDelay(task, &t); }
  131.  
  132.  
  133. /* 
  134. **    support macros for memory allocation from a task's heap memory manager.
  135. **    memory allocated from the task's heap will be automatically freed when
  136. **    the task exits.
  137. */
  138.  
  139. #define TTaskAlloc(task,size) TMMUAlloc(&((TTASK *) (task))->heapmmu, size)
  140. #define TTaskAlloc0(task,size) TMMUAlloc0(&((TTASK *) (task))->heapmmu, size)
  141. #define TTaskFree(task,mem) TMMUFree(&((TTASK *) (task))->heapmmu, mem)
  142. #define TTaskRealloc(task,mem,newsize) TMMURealloc(&((TTASK *) (task))->heapmmu, mem, newsize)
  143. #define TTaskGetSize(task,mem) TMMUGetSize(&((TTASK *) (task))->heapmmu, mem)
  144. #define TTaskAllocHandle(task,df,size) TMMUAllocHandle(&((TTASK *) (task))->heapmmu, (TDESTROYFUNC) df, size)
  145. #define TTaskAllocHandle0(task,df,size) TMMUAllocHandle0(&((TTASK *) (task))->heapmmu, (TDESTROYFUNC) df, size)
  146.  
  147.  
  148. /* 
  149. **    task accessor macros
  150. */
  151.  
  152. #define TTaskGetData(task)            ((TTASK *) (task))->userdata
  153. #define TTaskSetData(task,data)        { ((TTASK *) (task))->userdata = data; }
  154. #define TTaskPort(task)                ((TPORT *)(((TTASK *) (task))->port))
  155. #define TTaskBaseTask(task)            ((TTASK *) (task))->basetask
  156. #define TTaskHeapMMU(task)            &((TTASK *) (task))->heapmmu
  157. #define TTaskMsgMMU(task)            ((TTASK *) (task))->msgmmu
  158. #define TTaskSyncPort(task)            ((TPORT *)(((TTASK *) (task))->syncreplyport))
  159.  
  160.  
  161. TBEGIN_C_API
  162.  
  163.  
  164. extern TAPTR TCreateTask(TAPTR parenttask, TTASKFUNC function, TTAGITEM *tags)        __ELATE_QCALL__(("qcall lib/tek/task/createtask"));
  165. extern TAPTR TCreateTaskTags(TAPTR parenttask, TTASKFUNC function, TTAG tag1, ...)    __ELATE_QCALL__(("qcall lib/tek/task/createtasktags"));
  166.  
  167. extern TUINT TAllocSignal(TAPTR task, TUINT signals)                            __ELATE_QCALL__(("qcall lib/tek/task/allocsignal"));
  168. extern TVOID TFreeSignal(TAPTR task, TUINT signal)                                __ELATE_QCALL__(("qcall lib/tek/task/freesignal"));
  169. extern TVOID TSignal(TAPTR task, TUINT signals)                                    __ELATE_QCALL__(("qcall lib/tek/task/signal"));
  170. extern TUINT TSetSignal(TAPTR task, TUINT newsignals, TUINT sigmask)            __ELATE_QCALL__(("qcall lib/tek/task/setsignal"));
  171. extern TUINT TWait(TAPTR task, TUINT sigmask)                                    __ELATE_QCALL__(("qcall lib/tek/task/wait"));
  172. extern TUINT TTimedWait(TAPTR task, TUINT sigmask, TTIME *timeout)                __ELATE_QCALL__(("qcall lib/tek/task/timedwait"));
  173.  
  174. extern TBOOL TInitLock(TAPTR task, TLOCK *lock, TTAGITEM *tags)                    __ELATE_QCALL__(("qcall lib/tek/task/initlock"));
  175. extern TVOID TLock(TLOCK *lock)                                                    __ELATE_QCALL__(("qcall lib/tek/task/lock"));
  176. extern TVOID TUnlock(TLOCK *lock)                                                __ELATE_QCALL__(("qcall lib/tek/task/unlock"));
  177.  
  178. extern TPORT *TCreatePort(TAPTR task, TTAGITEM *tags)                            __ELATE_QCALL__(("qcall lib/tek/task/createport"));
  179. extern TPORT *TCreatePortTags(TAPTR task, TTAG tag1, ...)                        __ELATE_QCALL__(("qcall lib/tek/task/createporttags"));
  180.  
  181. extern TVOID TWaitPort(TPORT *port)                                                __ELATE_QCALL__(("qcall lib/tek/task/waitport"));
  182.  
  183. extern TVOID TTimeDelay(TAPTR task, TTIME *time)                                __ELATE_QCALL__(("qcall lib/tek/task/timedelay"));
  184. extern TVOID TTimeQuery(TAPTR task, TTIME *time)                                __ELATE_QCALL__(("qcall lib/tek/task/timequery"));
  185. extern TVOID TTimeReset(TAPTR task)                                                __ELATE_QCALL__(("qcall lib/tek/task/timereset"));
  186.  
  187. extern TINT TGetRandomSeed(TAPTR task)                                            __ELATE_QCALL__(("qcall lib/tek/task/getrandomseed"));
  188.  
  189.  
  190. /* 
  191. **    private functions.
  192. */
  193.  
  194. extern TINT TDestroyPort(TAPTR msgport)                                            __ELATE_QCALL__(("qcall lib/tek/task/destroyport"));
  195. extern TAPTR TTaskFindSelf(TVOID)                                                __ELATE_QCALL__(("qcall lib/tek/task/taskfindself"));
  196.  
  197.  
  198. TEND_C_API
  199.  
  200.  
  201. #endif
  202.